package com.bw.module_detail.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_detail.R
import com.bw.module_detail.model.entity.CommentEntity
import com.bw.module_detail.model.entity.VideoEntity
import org.w3c.dom.Text

/**
 * @author ykj
 * @date 2025-10-22 19:45
 * @description
 */
class DetailCommentAdapter:RecyclerView.Adapter<DetailCommentAdapter.VideoViewHolder>() {
    var videoList = mutableListOf<CommentEntity>()
    inner class VideoViewHolder (itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(dada:CommentEntity){

            itemView.findViewById<ImageView>(R.id.user_iv).apply {
                scaleType = ImageView.ScaleType.CENTER_CROP// 可选：图片居中裁剪，避免变形
            }.setImageResource(R.drawable.ic_launcher_foreground)// 替换为你的默认图片资源

            itemView.findViewById<TextView>(R.id.user_name).text = dada.nickname
            itemView.findViewById<TextView>(R.id.comment_tv).text = dada.content
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideoViewHolder {
        val view= LayoutInflater.from(parent.context).inflate(R.layout.item_comment,parent,false)
        return VideoViewHolder(view)
    }
    fun setData(data: List<CommentEntity>) {
        videoList.clear()
        videoList.addAll(data)
        notifyDataSetChanged()
    }
    override fun getItemCount(): Int {
        return videoList.size
    }

    override fun onBindViewHolder(holder: VideoViewHolder, position: Int) {
        holder.bind(videoList[position])
    }
}